<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}"
	rel="stylesheet" />
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-edit"
			th:object="${wxCode}">
			<input id="wxId" name="wxId" type="hidden" th:field="*{wxId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label ">微信号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="wxCode"
						id="wxCode" th:field="*{wxCode}" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">微信名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="wxName" id="wxName"
						th:field="*{wxName}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">appId：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="appId" id="appId"
						   th:field="*{appId}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">appSecret：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="appSecret" id="appSecret"
						   th:field="*{appSecret}">
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script
		th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script type="text/javascript">

		$("#form-role-edit").validate({
			rules:{
				roleName:{
					required:true,
					remote: {
		                url: ctx + "system/role/checkRoleNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
							"roleId": function() {
							    return $("#roleId").val();
							},
							"roleName": function() {
							    return $.common.trim($("#roleName").val());
							}
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				roleKey:{
					required:true,
					remote: {
		                url: ctx + "system/role/checkRoleKeyUnique",
		                type: "post",
		                dataType: "json",
		                data: {
							"roleId": function() {
								return $("#roleId").val();
							},
							"roleKey": function() {
							    return $.common.trim($("#roleKey").val());
							}
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				roleSort:{
					required:true,
					digits:true
				},
			},
			messages: {
		        "roleName": {
		            remote: "角色名称已经存在"
		        },
		        "roleKey": {
		            remote: "角色权限已经存在"
		        }
		    }
		});

        function submitHandler() {
            if ($.validate.form()) {
                edit();
            }
        }

		function edit() {
			var wxId = $("input[name='wxId']").val();
			var wxName = $("input[name='wxName']").val();
			var wxCode = $("input[name='wxCode']").val();
			var appId = $("input[name='appId']").val();
			var appSecret = $("input[name='appSecret']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/wxCode/edit",
				data : {
					"wxId": wxId,
					"wxName": wxName,
					"wxCode": wxCode,
					"appId": appId,
					"appSecret": appSecret
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}

	</script>
</body>
</html>
